<?php

namespace App\Http\Controllers\Mobile;

use App\Models\Banner;
use App\Models\Cate;
use App\Repos\ProductRepo;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{

    /**
     * 首页
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Request $request)
    {


        //分类列表
        $list  = Cate::select(['id','name'])->get();
        //banner
        $banner = Banner::get();
        //推荐商品
        $recommendItem = ProductRepo::recProduct();
        return view('mobile.index',compact('banner','list','recommendItem'));
    }



    /**
     * 分类商品列表
     * @param Request $request
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function cate2prod(Request $request)
    {

        $product['status'] = 'danger';
        $where['status']  = 1;
        if($request->cateId) {
            $where['cate_id'] = (int)$request->cateId;
        }

        $product['rs'] = ProductRepo::getListPages($where);


        if($product['rs']){
            $product['status'] = 'success';
        }

        return $product;

    }
}
